<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 两个数组的并集、交集、差集 （不能出现重复项），得到的结果是一个新数组
        const arr1 = [33, 22, 55, 33, 11, 33, 5];
        const arr2 = [22, 55, 77, 88, 88, 99, 99];

        //并集
        console.log('并集', [...new Set(arr1.concat(arr2))]);
        console.log('并集', [...new Set([...arr1, ...arr2])]);

        //交集:先对一个数组，去重。利用filter,然后找到在另外一个数据判断也没有这些项
        const cross = [...new Set(arr1)].filter(item => new Set(arr2).has(item))
        const cross1 = [...new Set(arr1)].filter(item => arr2.indexOf(item) >= 0)

        console.log('交集', cross);
        console.log('交集', cross1);

        //差集
        console.log('差集', [...new Set(arr1.concat(arr2))].filter(item => cross1.indexOf(item) < 0));
    </script>
</body>

</html>